/*
 * @Descripttion:
 * @version:
 * @Author: sueRimn
 * @Date: 2021-12-21 09:25:26
 * @LastEditors: sueRimn
 * @LastEditTime: 2021-12-22 15:01:45
 */
import User from "./user";

const login = {
  auth(params) {
    let userList = User.getUserList();
    let data = false;
    let rtn = false;
    params = JSON.parse(params.body);
    if (userList instanceof Array && userList.length > 0) {
      rtn = userList.find((item) => {
        return item.userName == params.userName && item.password == params.password;
      })
    }
    rtn ? data = { message: "登陆成功", code: 0, token: params.userName + params.password, userInfo: rtn } : data = {
      message: "登陆失败", code: 100
    }
    return data;
  },
  logout({ userId, userName }) {
    let userList = User.getUserList();
    let data = false;
    let rtn = false;
    params = JSON.parse(params.body);
    if (userList instanceof Array && userList.length > 0) {
      rtn = userList.some((item) => {
        return item.userName == userName && item.userId == userId;
      })
    }
    rtn ? data = { message: "退出成功", code: 0 } : data = {
      message: "退出失败", code: 100
    }
    return data;
  }
}
export default login